package com.example.smart_video.ui.activity;

import static com.example.smart_video.model.Constants.COUNT_STRANGER;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.example.cleandemo3.R;
import com.example.cleandemo3.databinding.ActivityLoadingBinding;
import com.wink_172.library.activity.SmartActivity;
import com.wink_172.library.model.Constants;
import com.wink_172.library.utils.DateUtil;
import com.wink_172.library.utils.MMKVTool;

import org.xutils.x;


public class LoadingActivity extends SmartActivity {
    private static final String TAG = "TAG";
    public ActivityLoadingBinding binding;
    private String[] PERMISSIONS = new String[]{
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
    };


    public static void startActivity(Context context, Object... args) {
        Intent intent = new Intent(context, LoadingActivity.class);

//      intent.putExtra(Constants.PARAM_DATA1, (String) args[0]);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_loading);
        binding.setOnClickListener(this);
        initView();

        String str = DateUtil.INSTANCE.getYear() + DateUtil.INSTANCE.getMonth2() + DateUtil.INSTANCE.getCurrentMonthDay() + COUNT_STRANGER;

        int count = MMKVTool.getInt(x.app(), str, 0);
        if (!checkPermissions(PERMISSIONS)) {
            requestPermissions(Constants.ACTIVITY_REQUEST_CODE3001, PERMISSIONS);

        } else {
            count += 1;
            MMKVTool.setInt(x.app(), str, count);
            Log.e(TAG, "count: ====>>"+count );
            if (count < 10) {

            } else {
                init();
                goNextActivity();
            }

        }


    }

    @Override
    public void onClick(View v) {
        super.onClick(v);

        getHandler().removeMessages(0);
        getHandler().sendEmptyMessage(0);

    }

    private void goNextActivity() {
        getHandler().sendEmptyMessageDelayed(0, 0);//表示延迟3秒发送任务
    }

    @Override
    public void handlerCallBack(Message msg) {
        super.handlerCallBack(msg);

        switch (msg.what) {
            case 0:
                MainActivity.startActivity(LoadingActivity.this);
//                SelectClassActivity.startActivity(LoadingActivity.this,0);
                finish();
                break;
        }
    }

    private void initView() {
    }


    private void init() {
//        String path1=com.wink_172.library.model.Constants.savePath + "root.txt";
//        if (FileUtil.isCacheFileExist(path1)) {
//            String str=readTxt(path1);
//            Config config= JSON.parseObject(str,Config.class);
//            binding.appName.setText(
//                    config.getStr());
//        } else {
//
//        }

    }


}

